<?php


namespace app\common\service;


use library\tools\Data;
use think\Db;

class MemberService {


    public static function recharge($mid, $num, $remark, $type = 'credit1') {
        $credit = round(db('meetyou_member')->where('id', $mid)->value($type), 2);
        $typestr = $type == 'credit1' ? '积分' : '余额';
        if (($credit + $num) < 0) return false;

        Db::table('meetyou_credits_record')->insert([
            'mid'        => $mid,
            'credittype' => $type,
            'num'        => $num,
            'credits'    => $credit,
            'create_at'  => time(),
            'remark'     => $remark
        ]);

        $credit = max(0, $credit + $num);
        Data::save('meetyou_member', ['id' => $mid, $type => $credit], 'id');
        return true;
    }
}